'''API database'''

#from spass.core.db.init_db_core import *
from spass.core.db.db_core import (core_get_users_list,
                                   core_add_user,
                                   core_del_user,
                                   core_add_user_to_team,
                                   core_del_user_from_team,
                                   core_get_teams_list,
                                   core_get_users_from_team_list,
                                   core_add_team_to_teamset,
                                   core_del_team_from_teamset,
                                   core_get_teamsets_list,
                                   core_get_teams_from_teamset_list,
                                   core_new_template,
                                   core_get_templates_list,
                                   core_create_assignment,
                                   core_get_assignments_list,
                                   core_info_user,
                                   core_info_team,
                                   core_info_teamset,
                                   core_del_team,
                                   core_del_teamset,
                                   core_search_user)


def get_users_list():
    '''Returns a list of all the "user" objects  in the "user" table'''
    return core_get_users_list()

def add_user(fullname, name):
    '''Adds an user in the "user" table.'''
    core_add_user(fullname, name)

def del_user(fullname, name):
    '''Deletes an existing user from the "user" table'''
    core_del_user(fullname, name)

def add_user_to_team(id_team, fullname, name):
    '''Add an existing user to the given team's id'''
    core_add_user_to_team(id_team, fullname, name)
    
def del_user_from_team(id_team, fullname, name):
    '''Delete an existing user from the team "id_team"'''
    core_del_user_from_team(id_team, fullname, name)

def get_teams_list():
    '''Returns a list of all "team" objects in the "team" table'''
    return core_get_teams_list()

def get_users_from_team_list(id_team):
    '''Returns a list of all "user" objects existing in the team "id_team"'''
    return core_get_users_from_team_list(id_team)

def add_team_to_teamset(id_team_set, id_team):
    '''Adds an existing team to the given teamset's id'''
    core_add_team_to_teamset(id_team_set, id_team)

def del_team_from_teamset(id_team_set, id_team):
    '''Deletes an existing team for the given teamset'''
    core_del_team_from_teamset(id_team_set, id_team)

def get_teamsets_list():
    '''Returns a list of all teamsets objects'''
    return core_get_teamsets_list()

def get_teams_from_teamset_list(id_team_set):
    '''Returns a list of all team objects from the given teamset's id'''
    return core_get_teams_from_teamset_list(id_team_set)

def new_template(title, test_path):
    '''Creates a new template'''
    core_new_template(title, test_path)

def get_templates_list():
    '''Returns a list of all existing templates objects in the database'''
    return core_get_templates_list()

def create_assignment(id_template, date, id_team_set, id_user):
    '''Creates an assignment'''
    core_create_assignment(id_template, date, id_team_set, id_user)

def get_assignments_list():
    '''Returns list of all assignments which exist in the database'''
    return core_get_assignments_list()

def info_user(fullname, name):
    '''Returns list of :
    - list of teams in which specified user belongs to
    - list of assignment in which specified user belongs to
    '''
    return core_info_user(fullname, name)

def info_team(id_team):
    '''Returns list of :
    - list of teamsets in which specified team belongs to
    - list of assignments in which specified team belongs to
    '''
    return core_info_team(id_team)

def info_teamset(id_teamset):
    '''Returns list of assignments in which specified teamset belongs to'''
    return core_info_teamset(id_teamset)

def del_team(id_team):
    '''Deletes a team from the database'''
    core_del_team(id_team)

def del_teamset(id_team_set):
    '''Deletes a teamset from the database'''
    core_del_teamset(id_team_set)

def search_user(fullname_regex, name_regex):
    '''Returns a list of users which match the specified regex strings'''
    return core_search_user(fullname_regex, name_regex)
